<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico">
  <link rel="mask-icon" href="/images/favicon.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"blog.upup.fun","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="用Pytorch训练LeNet-5实现手写数字识别，并将模型在浏览器端进行加载。">
<meta property="og:type" content="article">
<meta property="og:title" content="浏览器环境下加载CNN进行手写数字识别，并部署到gitee page">
<meta property="og:url" content="http://blog.upup.fun/2021/09/25/%E5%9C%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E4%B8%8B%E5%8A%A0%E8%BD%BDCNN%E8%BF%9B%E8%A1%8C%E6%89%8B%E5%86%99%E6%95%B0%E5%AD%97%E8%AF%86%E5%88%AB/index.html">
<meta property="og:site_name" content="猫头猫">
<meta property="og:description" content="用Pytorch训练LeNet-5实现手写数字识别，并将模型在浏览器端进行加载。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ss.im5i.com/2021/09/25/lJsvm.jpg">
<meta property="og:image" content="https://ss.im5i.com/2021/09/25/lJJeq.jpg">
<meta property="og:image" content="https://ss.im5i.com/2021/09/25/lJEUs.png">
<meta property="og:image" content="https://ss.im5i.com/2021/09/25/lJUiQ.png">
<meta property="article:published_time" content="2021-09-24T17:34:42.000Z">
<meta property="article:modified_time" content="2021-09-28T14:06:25.191Z">
<meta property="article:author" content="猫头猫">
<meta property="article:tag" content="react">
<meta property="article:tag" content="vite">
<meta property="article:tag" content="onnx">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ss.im5i.com/2021/09/25/lJsvm.jpg">

<link rel="canonical" href="http://blog.upup.fun/2021/09/25/%E5%9C%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E4%B8%8B%E5%8A%A0%E8%BD%BDCNN%E8%BF%9B%E8%A1%8C%E6%89%8B%E5%86%99%E6%95%B0%E5%AD%97%E8%AF%86%E5%88%AB/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>浏览器环境下加载CNN进行手写数字识别，并部署到gitee page | 猫头猫</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">猫头猫</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-works">

    <a href="/works/" rel="section"><i class="fa fa-smile fa-fw"></i>小作品</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://blog.upup.fun/2021/09/25/%E5%9C%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E4%B8%8B%E5%8A%A0%E8%BD%BDCNN%E8%BF%9B%E8%A1%8C%E6%89%8B%E5%86%99%E6%95%B0%E5%AD%97%E8%AF%86%E5%88%AB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="猫头猫">
      <meta itemprop="description" content="如果我是一只小猫咪，每天只要喵喵叫。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="猫头猫">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          浏览器环境下加载CNN进行手写数字识别，并部署到gitee page
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-09-25 01:34:42" itemprop="dateCreated datePublished" datetime="2021-09-25T01:34:42+08:00">2021-09-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>
            <div class="post-description">用Pytorch训练LeNet-5实现手写数字识别，并将模型在浏览器端进行加载。</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>尝试一下用Mnist数据集训练一个简单的CNN网络，然后搭建一个静态页面，在浏览器端加载模型使用canvas区域的内容预测手写数字。模型使用Pytorch编写，用cpu训了10个epoch之后导出为onnx模型。之后在浏览器端通过onnxruntime-web进行加载，并进行预测。</p>
<p><img src="https://ss.im5i.com/2021/09/25/lJsvm.jpg" alt="这是一个2"><br><img src="https://ss.im5i.com/2021/09/25/lJJeq.jpg" alt="这是一个7"></p>
<h1 id="模型"><a href="#模型" class="headerlink" title="模型"></a>模型</h1><p>模型代码其实网络上已经有很多了，原理和细节也不再赘述；需要注意的是，输入是一个Batchsize x 1 x 28 x 28 的矩阵，输出为Batchsize x 10的矩阵也就是说第一维是动态的，这就决定了我们在导出为onnx模型时的写法：<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">transformToOnnx</span>(<span class="params">model, batch_size, name=<span class="string">&#x27;mnist.onnx&#x27;</span></span>):</span></span><br><span class="line">    model.<span class="built_in">eval</span>()</span><br><span class="line">    x = torch.randn(batch_size, <span class="number">1</span>, <span class="number">28</span>, <span class="number">28</span>)</span><br><span class="line">    torch.onnx.export(model, x, name, export_params=<span class="literal">True</span>, opset_version=<span class="number">11</span>, do_constant_folding=<span class="literal">True</span>, input_names=[</span><br><span class="line">                      <span class="string">&#x27;input&#x27;</span>], output_names=[<span class="string">&#x27;output&#x27;</span>], dynamic_axes=&#123;<span class="string">&#x27;input&#x27;</span>: &#123;<span class="number">0</span>: <span class="string">&#x27;batch_size&#x27;</span>&#125;, <span class="string">&#x27;output&#x27;</span>: &#123;<span class="number">0</span>: <span class="string">&#x27;batch_size&#x27;</span>&#125;&#125;)</span><br></pre></td></tr></table></figure><br>首先需要使用model.eval()将模型切换为预测模式，接下来我们随机生成一个输入的参数，也就是Batchsize x 1 x 28 x 28大小的一个随机矩阵。在导出时需要指定导出的路径，输入和输出的符号（上边的写法意思是在后续加载模型的时候，输入变量名为input，输出变量名为output）。同时由于输入和输出的第一维都是batchsize，因此把它们指定为动态轴。</p>
<h1 id="前端实现"><a href="#前端实现" class="headerlink" title="前端实现"></a>前端实现</h1><h2 id="初始化工程"><a href="#初始化工程" class="headerlink" title="初始化工程"></a>初始化工程</h2><p>首先采用vite初始化一个react-ts项目，这一步没有太多注意事项。</p>
<h2 id="模型的加载和预测"><a href="#模型的加载和预测" class="headerlink" title="模型的加载和预测"></a>模型的加载和预测</h2><p>为了加载模型，我们需要使用onnxruntime-web。onnxruntime-web是一个可以在浏览器环境下和nodejs环境下加载onnx模型的库，可以在CPU和GPU上运行，CPU使用web assambly来加载模型，而GPU使用Webgl来加载，默认运行在CPU上。两种方案支持的符号集不同，wasm方式支持全部的符号集，而webgl方式仅仅支持一部分符号集（具体的说明参考文献[1]）；除此之外，在ios的chrome、edge和safari浏览器中仅支持wasm。本次小实验导出的模型如果采用webgl加载，就会遇到上边提到的符号集的问题，因此采用wasm加载模型。我们只需要：<br><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add onnxruntime-web</span><br></pre></td></tr></table></figure><br>便可以在工程中安装这个包了。</p>
<p>接下来我们需要对vite工程进行一些配置。由于vite在启动server时有一个pre-bundle的过程，使用esbuild将各种非标准的模块转化为es6模块。onnxruntime-web中使用到了export namespace xx的写法，这些会在pre-bundle的时候报错，因此我们可以选择通过pre-bundle过程；</p>
<p>同时，即便我们跳过了pre-bundle的过程，我们会发现在项目启动之后，onnxruntime-web会自动的去static/js路径下去找两个wasm文件，而在启动服务和打包的时候并不会自动的加入这两个文件。而如果我们引入cdn上的onnxruntime-web库，我们会发现它会自动地去cdn地址请求wasm文件，cdn上这两个文件自然是存在的。参考onnxruntime给出的demo[2]，可以看到，官方在使用webpack打包的时候也是使用了CopyWebpackPlugin将对应的文件拷贝到打包之后的目录中。为了方便开发和打包，建议首先跳过pre-bundle过程，然后采用cdn加载onnxruntime-web包，并在vite.config.js中声明该包为external，即：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// vite.config.js</span></span><br><span class="line"><span class="keyword">import</span> &#123; defineConfig &#125; <span class="keyword">from</span> <span class="string">&#x27;vite&#x27;</span></span><br><span class="line"><span class="keyword">import</span> react <span class="keyword">from</span> <span class="string">&#x27;@vitejs/plugin-react&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; viteExternalsPlugin &#125; <span class="keyword">from</span> <span class="string">&#x27;vite-plugin-externals&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// https://vitejs.dev/config/</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> defineConfig(&#123;</span><br><span class="line">  <span class="attr">plugins</span>: [</span><br><span class="line">    react(),</span><br><span class="line">    viteExternalsPlugin(&#123; <span class="comment">// 声明为external</span></span><br><span class="line">      <span class="string">&#x27;onnxruntime-web&#x27;</span>: <span class="string">&#x27;ort&#x27;</span></span><br><span class="line">    &#125;)</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">optimizeDeps</span>: &#123;</span><br><span class="line">    <span class="attr">exclude</span>: [ <span class="comment">// 跳过pre-bundle</span></span><br><span class="line">      <span class="string">&#x27;onnxruntime-web&#x27;</span></span><br><span class="line">    ] </span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">base</span>: <span class="string">&#x27;/mnist-demo/&#x27;</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><br>然后在index.html中加上库的cdn地址：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></p>
<p>接下来的过程其实就很简单了，我们成功的引入了onnxruntime-web库，然后需要用它来加载模型，并进行预测：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">    <span class="comment">// 加载模型</span></span><br><span class="line">    <span class="keyword">const</span> session = <span class="keyword">await</span> ort.InferenceSession.create(model);</span><br><span class="line">    <span class="comment">// 输入数据，第一个参数是数据类型，第二个参数inputArray是一个一维数组，第三个参数表示的是维度，注意需要和之前模型导出时定义的维度相一致，即：dynamic x 1 x 28 x 28</span></span><br><span class="line">    <span class="keyword">const</span> inputs = <span class="keyword">new</span> ort.Tensor(<span class="string">&quot;float32&quot;</span>, inputArray, [<span class="number">1</span>, <span class="number">1</span>, <span class="number">28</span>, <span class="number">28</span>]);</span><br><span class="line">    <span class="comment">// 使用run进行预测，需要注意的是，输入和输出与之前导出时定义的输入输出变量名一致</span></span><br><span class="line">    <span class="keyword">const</span> outputs = <span class="keyword">await</span> session.run(&#123;</span><br><span class="line">        <span class="attr">input</span>: inputs,</span><br><span class="line">      &#125;);</span><br><span class="line">    <span class="comment">// 预测结果</span></span><br><span class="line">    <span class="built_in">console</span>.log(outputs.output.data);</span><br></pre></td></tr></table></figure></p>
<p>到此为止，在浏览器加载模型的部分就完成了，接下来只需要想个办法获取到用户输入的数据，并使用这些数据进行预测。</p>
<h2 id="获取输入数据"><a href="#获取输入数据" class="headerlink" title="获取输入数据"></a>获取输入数据</h2><p>模型输入是1x28x28的图片，而让人在屏幕上手动的去在一个28像素x28像素的区域内绘制肯定是个不现实的事情（太小了）。因此我们需要把输入的canvas放大（这里采用的是300x300），在预测时对画布的输入进行缩小,并转化为单通道。</p>
<p>为了获取到这个300x300区域内的像素数据，我们使用canvas.getImageData()获取到这个区域内的rgba数组。接下来，我们需要将它缩放为28x28的大小。这里引入了pica库，使用pica的resizeBuffer函数对像素区域进行缩放。</p>
<p>由于canvas的默认颜色是黑色透明，因此我们拿到的数组的非画笔区域的rgba值为(0,0,0,0)。同时注意到模型的输入中，灰度的取值范围为-1-1，因此为了保留单通道，我们保留a，并将其根据是否为0，简单地映射到-1和1就够了。</p>
<p>还需要注意的是，由于画布会从300x300缩放到28x28，因此canvas画笔的粗细也是一个影响效果的因素：如果画笔过细，缩放之后画布区域的像素值都是0，也就没有效果了；如果画笔过粗，可能缩放之后，原本隔着很远的两个区域变成了邻居，也会影响效果。</p>
<p>最后，我们只需要根据上述操作，根据缩放、处理过后的数组构建输入的Tensor，并传入模型进行预测就可以了。</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>到这里，其实模型的加载、预测和如何获取输入数据都已经完成了。最后就是把以上的东西串起来。实际的效果就是最上边两张图的样式，我把它放在了gitee page上，实测网络请求的速度还可以接受：<br><img src="https://ss.im5i.com/2021/09/25/lJEUs.png" alt="加载速度"><br>同时我也把它部署在我的服务器中，模型丢到cdn上，速度也还可以接受（gzip对模型好像压不了多少呀。。）：<br><img src="https://ss.im5i.com/2021/09/25/lJUiQ.png" alt="加载速度"></p>
<p>也就是说，对于一些简单的模型，我们完全可以丢到gitee page上进行使用，还是蛮好玩的。</p>
<p>最后丢个页面地址和仓库地址，有人需要的话我再去补readme，球球点个关注和star吧：</p>
<h3 id="页面地址："><a href="#页面地址：" class="headerlink" title="页面地址："></a>页面地址：</h3><p><a target="_blank" rel="noopener" href="http://maotoumao.gitee.io/mnist-demo/">Gitee Page版本</a></p>
<p><a target="_blank" rel="noopener" href="http://example.upup.fun/mnist">部署到nginx的版本</a></p>
<h3 id="仓库地址："><a href="#仓库地址：" class="headerlink" title="仓库地址："></a>仓库地址：</h3><p><a target="_blank" rel="noopener" href="https://github.com/maotoumao/mnist-demo/">Github仓库</a></p>
<p><a target="_blank" rel="noopener" href="https://gitee.com/maotoumao/mnist-demo">Gitee仓库</a></p>
<p><a href="http://blog.upup.fun">个人博客</a></p>
<p><a href="http://blog.upup.fun/2021/09/25/%E5%9C%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83%E4%B8%8B%E5%8A%A0%E8%BD%BDCNN%E8%BF%9B%E8%A1%8C%E6%89%8B%E5%86%99%E6%95%B0%E5%AD%97%E8%AF%86%E5%88%AB/">原文地址</a></p>
<hr>
<h3 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h3><p>[1] onnxruntime web: <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/onnxruntime-web#Operators">https://www.npmjs.com/package/onnxruntime-web#Operators</a></p>
<p>[2] onnxruntime-web使用demo <a target="_blank" rel="noopener" href="https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js/quick-start_onnxruntime-web-bundler">https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js/quick-start_onnxruntime-web-bundler</a></p>

    </div>

    
    
    
        <div class="reward-container">
  <div>嘻嘻</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="猫头猫 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="猫头猫 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/images/wechat_channel.jpg">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/react/" rel="tag"><i class="fa fa-tag"></i> react</a>
              <a href="/tags/vite/" rel="tag"><i class="fa fa-tag"></i> vite</a>
              <a href="/tags/onnx/" rel="tag"><i class="fa fa-tag"></i> onnx</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/07/23/%E5%9C%A8docker%E7%8E%AF%E5%A2%83%E4%B8%8B%E9%83%A8%E7%BD%B2webIDE/" rel="prev" title="在docker环境下部署webIDE">
      <i class="fa fa-chevron-left"></i> 在docker环境下部署webIDE
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/12/04/%E6%91%B8%E9%B1%BC%E5%B0%8F%E6%8A%80%E5%B7%A7%E2%80%94%E2%80%94%E4%B8%80%E4%B8%AAchrome%E6%8F%92%E4%BB%B6%E6%8A%8A%E7%BD%91%E9%A1%B5%E5%8F%98%E6%88%90%E6%8B%BC%E5%9B%BE%E6%B8%B8%E6%88%8F/" rel="next" title="摸鱼小技巧——一个chrome插件把网页变成拼图游戏">
      摸鱼小技巧——一个chrome插件把网页变成拼图游戏 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
      <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=477844082&auto=1&height=66"></iframe>

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%89%8D%E8%A8%80"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%A8%A1%E5%9E%8B"><span class="nav-number">2.</span> <span class="nav-text">模型</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%89%8D%E7%AB%AF%E5%AE%9E%E7%8E%B0"><span class="nav-number">3.</span> <span class="nav-text">前端实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E5%B7%A5%E7%A8%8B"><span class="nav-number">3.1.</span> <span class="nav-text">初始化工程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A8%A1%E5%9E%8B%E7%9A%84%E5%8A%A0%E8%BD%BD%E5%92%8C%E9%A2%84%E6%B5%8B"><span class="nav-number">3.2.</span> <span class="nav-text">模型的加载和预测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE"><span class="nav-number">3.3.</span> <span class="nav-text">获取输入数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">3.4.</span> <span class="nav-text">总结</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%A1%B5%E9%9D%A2%E5%9C%B0%E5%9D%80%EF%BC%9A"><span class="nav-number">3.4.1.</span> <span class="nav-text">页面地址：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%93%E5%BA%93%E5%9C%B0%E5%9D%80%EF%BC%9A"><span class="nav-number">3.4.2.</span> <span class="nav-text">仓库地址：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="nav-number">3.4.3.</span> <span class="nav-text">参考文献</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="猫头猫"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">猫头猫</p>
  <div class="site-description" itemprop="description">如果我是一只小猫咪，每天只要喵喵叫。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">31</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">27</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/maotoumao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;maotoumao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:lhx_xjtu@163.com" title="E-Mail → mailto:lhx_xjtu@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">猫头猫</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">91k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">1:22</span>
   | <a href="http://beian.miit.gov.cn/" rel="noopener" target="_blank">陕ICP备20005224号-2 </a>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

  

</body>
</html>
